fixed error trying to access a local variable