Improvements on code and ansatz

See commit message for details.
Please note that I found plenty of failed tests. Please consider them before applying the PR.

sincerely