Added and fixed compare function