Remove subshells & simplify code to work with bash & zsh