add comments/ refactor javascript