Added 3D case to watershed kernel, and abstracted some index manipulation