Implement modification 1.

I've only prove it correct, not actually tested it.