fixed checking for tty