Bugfixes and cleanups.