Added support for encryption, fixed things