Fix undefined local variable error