Move majority of js into a separate file