Moved code out of script tag