massive refactoring to support IE