Adding comments and refactoring