General code cleanup, and switch direct code for parse_rules