Fix substring bug