Cleanup, bugfixes etc