code duplication fixes