Fixed variable mess

Compiles, but some errors appeared during runtime.