Adding JSDoc
Some refactorization