Fix bug with first chunk overshooting both the start and the end of the slice. Also some small variable changes.