Code cleanup

4 commits that cleanup code by using more shell built-ins.
We probably should add some unit tests for this. What if you extract this to a function? Then adding a test is even easier.