Remove some duplicate code