Allow the option of choosing whether recusive searching of directories is used.
Also cleans up the code in the main script a little.