updated search code to return json and fixed search errors