fixing error with undefined local variable