made the function for generating the datasets more robust