for-each-ref: Fix sort with multiple keys