Bugfixes

Lots of bugfixes.