End the server and correct some bugs