Completely eliminated SQL from build_dense_matrix