First stab at eliminating duplicate code.