Removed open and added check for tty