refactored implementation working with new tests