Search optimization and null checks