adding comments and logic

adding logic and comments