Fix begin and end markers for nested scopes.