Fixes to squared variables code.
Fiddled with this trying to fix a bug.