BUG: fixing incorrect nesting, code refactoring

The code corresponds to the version 4 of the SR object
stored here: http://slicer.kitware.com/midas3/item/128215