Most of the bugfixes.