Fixed bug in index sort by