final edits.  tried another function but couldn't make one work. flowchart added.