Fixed bug causing an exception due to an undefined variable