Refactored several things