Rule hash

This is @pradeep90's PR with one little optimization.