Refactoring the part relating to the quadratic matrix to its own function
Removed dead code
Precomputation of structure to create quadratic matrix