Key sort the options before applying them.

This fixes issues between page() and limit(). Page needs to be applied
after limit. There are other more fancy ways to implement this
dependency, but ksort() was the fastest solution.

Fixes #3159