removed duplicate code

added some comments