Refactored a bunch of stuffs