Fixed error in search and simplified scan_directory