added a check to populatedistinctvals to prevent errors