Better implementation of useful prefixes.

A sorted and filtered array is now passed to the original implementation.

Fixes #53