factor js into its own file
tweaking some more