added some comments, refactored some methods