Some improvements and many bugfixes