Ran shellcheck, implemented suggestions.