remove some code duplication