added error handling and search bounds