fixed logic error in compare method