Better error checking, run as script, use exit codes