Replace fold and foldWithKey with foldr and foldrWithKey, Cleanup

- Replace in PrefixTree and DocIdMap
- Minor cleanup
- Add a few comments