Adds more functions to JavaScript

This update adds two more functions into the JavaScript file. Its also
fixes some bugs and cleans up the code.