added comments and small refactor