bug fixed. sorting part