reorganize code , add collection stats