fixed one severe logic bug
still not working, but at least variables don't get corrupted anymore