Added/updated some code documentation and did some minor refactoring.