refactoring js in prep for new features