Refactored and simplified deep extend method