Lotsa bugfixes, cleanup, etc.