removing code duplication, adjusting test