This line here is the thing the ticket is trying to fix? Is this all? The rest to make testing it easier and cleaning up code?

So do you need the "index" variable here, or can you just ask the cref for it's index value? Do you even need to sort if you do that? Perhaps I am using hallucinogenic drugs. Let me know if so. 

Beyond clarifying this bit here, this pull seems sane enough to me.