fixed some bugs pointed out by WizardCM