Fixed compare.py

Hello,

I found possible bugs and wonder if you consider to apply this patch.