fix readding directory
close scope on error
fix setting of read/write settings
close scopes