rewriting server code #2