first batch of bugfixes

first batch of fixes for PR#24