adding comments and small refactory