A bugfix and further code cleanup.