fix encryption and encoding, tweak API