(Michalis: Changed functions to include index)