Reduce code by factoring