Replace shallow copy with deep copy of arrays