adds better error handling to search
this is going to be really fun to refactor some day