Some useful changes

One bugfix and two new features.

Are these acceptable?