fixed race condition against window.onload