Bug797

Here's an implementation for bug 797.