fixing irksome bug in generate_audio plus a bunch of other stuff