Fix crashing bug in search