cleaning mainloop & close