Improved IE9 compatibility, fixed a few other annoying bugs, minor code reformatting