Rewrote setup.sh to use functions

This PR is to fix issues from #14 fresh pull as recommended by JT.