add comments and refactorings