Fixed bugs in model