replace array_merge with manual iteration for performance