Cleaned up the shell script. It looks much nicer now, and is easier to edit.