Bugfix and generalization in one.