Improve autogenerate script