Fix for #118. 

This code needs further testing, but the same changes to my local encrypted store (based on an earlier release) fix #118.