revised and refactored encryption process