added optional encryption