Several improvements and bugfixes