lots of bug fixes.  close to a template