updated orderdiff function