Doc + minor code reorganization