Refactored efficientInsert to use map