Fixed bugs in model.