solved sorting problem and enhanced backand sorting