Improved diff functions