fixed race condition when saving models, added a locking facility