clean up and document javascript