RMS: fix unflattening of statements to handle ambiguity better, search if first option fails, etc. Untested.