refactor some JS.  Update docs