modfied compare code