Some code improvements on both server and models

Some changes has been made on both server.js and models.js files.