fixed bugs where scripts ran before page had loaded