add proper main loop and fix blocking getch()