Refactor crypto

Fixes #86 among other things