using splice instead of slice