fix a bunch of bugs from pull request
fixup some more bash issues