Implemented readyState check to enable IE8 to work