Added error handling to Map in case it fails to allocate enough memory.