As published

Actually, not quite. Published as penultimate dev version, and fixed
before pushing to master.
Original code