I think you can remove the first zipWithIndex and your map(_._1) to simplify this a little bit.