Extract logic to wait user input