Optimized waitForPageLoad and added timeout