Bugfix and performance optimization