Changed the way to check document ready.