changed flow.rb to while loop