Fixed server not stopping properly in some cases