some code consolidation, some more comments