Cleanup and bugfixes.
Cleanup and bugfixes [2].