Fix to overlay JSON encoding function