add comments and refactor tests