Merge new stuff

This is basically a complete rewrite.  Oh well!