Fix incorrect usage of substr