Fixing bug in search method