Once again, not to sound like a broken record, we could have done some much more to improve our code base....
Why didn't we extract that function into a more testable place?
In order for the code to become more clean and modular, we should try to always write tests whenever we make changes to the code, even if that means extracting a small portion (ie. the onLoad function)