Change expand to use typeof instead of instanceof