Fix access to undefined local variable