Bugfixes

I ran in to some bugs and tried to fix them. Commit message try to explain the problems I faced.