Bugfixes

General bug fixes and testing