Fixed undefined variables

First working version