Bug fix: for weird case where the dictionary stores keys in different order