Bugfixes

Various bug fixes.