Refactored a bunch of stuff