Fixed #715, and some misc cleanup.