CODE REFACTORING: Refactored the existing code for insert ad