Remove some repeated code