fixing undefined local variables