Optimization: use typeof instead of Array.isArray