added sorted output option