Fixed infinite onload check