Simplify onbeforerequest

I pulled out the miscellaneous / minor performance changes I had in my Switch Planner branch to go in separately.