Refactor the crypto code after a very helpful conversation