Refactor into packages