refactored implementation.