rewrite glob expansion flattening algorithm, closes #3