Refactored things a bit