Undefined variable bug fixes

A number of variables were incorrectly defined (broken)