Cleanup and bugfixes.