Use a map for quick look up instead of doing linear search for index.