Cleanup + bugfixes.