added error handling
removed debug print
fixed bug where a single search pattern would get interlaced with spaces