Refactoring: make prompt loop a utility function.