some code improvements on both server and models