Reorganised code so now the crypto library stands by itself.