refactored code, added some comments