Refactored a bunch