In fact only line 38 needs to be replaced :-)
Line 39 only needs to set tempU[0,0], tempU[0,-1] etc