refactor build_collections functions