Use mb_substr instead of substr for safety

This fixes #67.