Use correct substring indices

Fixes #1