added search and better error handling