Minor cleanup and bugfixes