Fixed unbound vars and implemented some bash good practices