fix some bugs in matrix loading