Move some common code into utility methods.