Fixed bugs added by previous commit