refactored some more
renamed some functions
removed some redundant comments
extracted some new functions