Fixed a few bugs in model.