Improving the ingest_directory() function