trimming multi-dimensional arrays