significant refactor of javascript for the sake of #24 - closes #24
minor formatting