Cleanup and bugfix