Replaced hardcoded wait before check for document.readyState