Refactor source dict building to reduce code duplication