Lots of detail cleanup and bugfixes.