I think I am close to getting this to do what I want (for a first attempt)