fix test
add jsdoc, minor refactoring