Refactoring slice cutting loop.