A whole bunch of bugfixes. Regtests now work