Update run.sh

Many additions in code, but mostly functions that need testing.