Fix bugs on server stopping