Rule duplicate keys

I've made some changes over @jamesallardice's previous code. Tests are passing.