original sorting method