Changed instaceof conditonal to typeof