Refactoring:
Slight performance improvements here and there. Added clarifying inline documentation in a few places.