Added comments, refactoring