Major refactor - stabalised on ie 10