Sort object keys to work around ordering bug

Ruby 1.8.3 doesn't sort keys in hashes which gives inconsistent results.