Move script before page load to avoid flickering