refactored model builder to query builder and mapper