Refactor encryption