common code for storage