Fix recursive search and threading

Introduces a garbage collector to eliminate memory corruption when
searching directories recursively.