Updated with similar logic to that used in the user_permissions branch, but all extracted to a seperate class for doing all fetch and collapse work.