Refactored difference finding logic