simplifications, increased consistency

` `   and  $(  ) were both used - changing to more consistent $(  ).
simplified flow control.
changed to bash internal provisions instead of shelling to external commands where easily possible.