clean up js a bit and add comments