search main algorithm completed and roughly tested.