Refactor for more reuse and better encapsulation