updated for non-empty directories