Fixed bug in model caching and put in some sanity checks