Review and fix hdist based lookup logic