Refined rules. Added more tests.