updated to have sort feature
added sorted output