refactore all code for encrypting