Fixed an NPE when closing down the terminal