Factor out code into module