plenty of terminal handling fixes