implemented main loop and input method