Delegated most user input code to separate module

Code is much less convoluted now.