Fixed unbound vars and implemented some bash good practices

The rationalle for changing the first 2 lines can be found here: http://kvz.io/blog/2013/11/21/bash-best-practices/
The reason for this change and the one on line 99 is this (from the getopts manpage): If an option character not contained in the optstring operand is found where an option character is expected, the shell variable specified by name shall be set to the <question-mark> ('?')  character. In this case, if the first character in optstring  is  a  <colon> (':'),  the  shell  variable OPTARG shall be set to the option character found, but no output shall be written to standard error; otherwise, the shell variable OPTARG shall be unset and a diagnostic message shall be written to standard error.