add jsdocs for loader. small code refactoring