Moved creation of matrices to own functions