Fix getSubstring bug