works version - with encryption