change slow implementation to hash table