fix for duplicate expansions and fix for regression introduced in last commit