Updated compare function

Removed repetition of matching positions