Bugfixes

Several minor bugfixes and enhancements.