refactoring, inlining and more compatibilty (works in IE8 now)