Add directory support
Fix two assertions
Small performance improvement