added sorting in history