(no need to replace the diagonal(1) but it's a bit less efficient)