[server] Improved code and added comments