Fix possible NPE in searching code.