fix for IE bug and some refactoring