Replace Mat with Matrix in scv
Do speed/memory optimization