Memory leak fixed + naming in the matrix functions