Bugfixes

And a few changes.