Fix auto-generate scripts to be more flexible