adding a rule 'where condition' inside optimize function