Fixed problem with global variable in function.