cleaned up js:
 - factor out functions
 - variable and function names
 - comments
 - **formatting**