Add comments for JSDoc and some refactors