...and now I see that only handled top-level statements. This one works with nested ifs and variables too.