Refactor after review feedback

Refactored the main `saveOrUpdate` method into smaller methods based on review feedback