refactored make_matrix