refactor linear search