Fix a bug in `expand` which causes infinite recursion.