Fix #498.

And cleaned up some unused code.