moving main loop and input handling