More tests and resulting bugfixes

Change-Id: Id143b015361c10f9ce7e692a1d41ab81f4c84107