Added better code to deal with missing directories.