Nested ifs are broken

This PR adds a test for broken nested ifs.

At the moment I cannot really say where the bug is but it seems that a68318f4c55be035f6d82dbca3211f6dc95ccda7 brought the bug into the code.