changed to solution not requiring isArray