The algorithm, in a basic form, now works.