Added some more intelligence to the shell scripts