implemented rules.  working, but theres a small code mess