refactored to use map