Factor map

Factor out a map function.