factoring out code for reuse