More fixes to the last commit

RMG-Py data structure is non obvious that it was really hard to see the mistake!
Suprisingly RMG-Py did not crash but just went into endless loop.