Use SliceTricks to simplify the code