Refactor setup of TTY
Refactor of user input handling