Starting to move all multi-line actions in key command loop into their own functions. Starting with wait action.