Few bugfixes

A new test cases that came with a few bugfixes...