Moved js to external files

Should hopefully help with code clarity