code improvement for model saving server-side