Added code for rules matching