Bidirectional sorting implemented