Cleaning and bugfixes