cleanup encryption code, improved return codes

improved return codes to handle failures during initial encryption