Cleanup and bugfixes. Lots more to come.