fix encryption bug, cleanup