Various bugfixes

See referenced issues in commits