sorting restored and modulized