add JSDoc & code refactoring