Fixed bugs in validation