Bugfix and cleanup