refactored with shellcheck