Remove some code duplication