document: Javascript documentation and simple refactor