Refactor code into packages