improve pty handling