Added checks for empty slices