Added improved search code