Moved major functions outside of onload callback