Working version of generate.sh