improve script handling of when page is ready to run. Should handle long page loads better