Refactored

Moved a few things around for efficiency, added a bit of helping
comments