Improved rule compile function, and add test for it.