refactored the generating and testing code