Fix several _killer_ bugs. This now actually WORKS for really complex testcases :)