Safety nets against ill-conditioned matrices, added test-mode parameter.