Added check to make sure the necessary temporary directories exist.