refactored using a map function