Small adjustment to tty handling. Needs testing