Moved map logic from controller to a service.