Some more cleaning and bugfixes