Whenever you see a tail.foldLeft(_.head), you can replace with a reduce.