Many improvements and bugfixes