rewrite Compare function, should be better