Optimised search algorithm.
Minor changes.