improve save and load model function