set stty back on exit + refactorings