bugfix and cleanup.