Rewrite to make it less dependent on Internet Explorer since it doesn't work well in IE9...