rewrite server stop logic