improved server code