Slicing algorithm. Not tested