Various bugfixes

Lots of little changes to improve things