More refactoring

Trying to use more idiomatic bash