Fix doc for get_refined_structure. Switch to returning a sorted structure.
Add unittest.