fixed error trying to access field on undefined variable