added compare previous but work with wrong order