Issue #401: Add a generic sorting function.