Fixed errors due to possibly undefined variables