JS doc and little code refactoring