Refactor into packages

Sorry, but I completely forgot about this!