Refactor doc collection, block, and add custom error