Fix rules and add some checks to prevent future mistakes;