Some improvements and bugfixes