uncommented Teja sorting code