Misc fixes to crypto code