Modify Array.cast and implement query recursiveness