Refactored a bunch of stuff to make more sense