Improved generate script