Bugfixes and improvments