Tested implementation; first draft.