refactor compare functions