Updated matrix to work with c-strings, misc memory cleanup