cipher refactored