Sort map keys properly to prevent failures when keys are heterogeneous

Fixes #7