Fixed bug in writing back to model.