refactored diff_main method to reduce complexity