Refactor, document, and cleanup the KDF