fixed up rule machine, now works as expected with lua, and has error handling capabilities