refactor collective code to enable caching impl (TODO) and fix some semantic errors