Code updated with an edition to deal with longer data sets