linear search and finished optimisation