original working version with a small change - pulled a hashmap initialization out of main while loop in apply_unary_rules