bugfix and cleanup (combined commit)