Several improvements and bugfixes.