Added ternary search