Fixed backward sorting, added toy reference code