Improved the logic in the DataGenerator