Change nested while loop to unless/next for readability