Rewrote variable tracking code for future expansion