made search better and put the error case first!