Use hash to decrease complexity