Refactored lots of stuff