fix compatibility issues
fix references
more fixes
add some debug messages
Merge pull request #1762 from matiu/fix/encrypt-compat

Fix/encrypt compat