IE8 fixes and refactoring