Added basic termios functionality; cleaned up code