Restructure generate script.