this seems to work after fixing the deep copy of arrays issue