Improve the KeyValueValidator code