adds more logic to the get_longest method