Changing the implementation to use hashmap