refactor debug mode

follow shellcheck hints