new and more robust wavesim script