code hardening, logic improvements