implement matrix using cpp, much memory gain
remove useless code