Adding some comments and small refactoring