fixed issue with memory storage of matrix