modified some things so it runs ok on IE8