Remove some duplicated code