Adding a test case not covered before.
Fixed, refactored and simplified things.
Still more fixes (0 to null ptr conversion, enum check). The additional test passes now too.