IE8 compatibility

Made (hopefully) all changes necessary for IE8 compatibility.