Bugfixes and style improvements