Refactored mapper code for building collections.