I think this would read cleaner and be faster if we just had two functions that are defined differently at load time instead of switching so much at runtime.