"Boxes" from lines on complex surface

Hey !

I wanted to make "boxes" from a random linework on a surface, did it so :

But, because there is one, I just cannot figure how to have straits angles and not some curvy ones. 

Any help would be appreciated =3
And if you got a simpler solution, I'm interested

Thx in advance !