added sorted functionality