Write ServerFactory and rewrite main to use it