Added rewriting of boolean expressions and tested.