Add getch, error routines

- Refactor main
- No change in functionality