Matrix optimization of the kopt procedure.
kopt optimization working.