Improved linear search algorithm