Refactoring stuff... (in progress. shouldn't be broken, but things might be pretty weird)