Added some control flow using while loop and if/else.
Added pry for debugging.