Fixed undeclared variable bug