Several bugfixes

closes #248
closes #239
closes #187