revisions to manuscript and most of the code