add tests for to and deleted variables, fix bugs found