improved code in ServerHandler