First draft of rules engine

to review