Remove repeated code