mostly done.  need to tidy and comment code.