also move protected variable resetting into the correct scope