typeof --> isArray check

And some code cleanups