Changed the ordering logic