Added shutdown hook for restoring the terminal