Improve server login code