Some re-arranging/refactoring.  Now done (I think) with an untested SHA-256