Replacing sky - almost finished

I have simple task which I almost figured out but cannot get to end.

I have simple task - replace sky in random shot of train emerging from bridge. I was first trying to do it with chroma key but there was a problem as sky was both blue and white so it was mess (which was even slightly moving).

So I decided to go oldschool and using ColorCorrection and Invert nodes I created an matte (see fig 1 in my screenshot as seen from Viewer1). Then using Shuffle node I made alpha channel out of red and used original footage to get colors.

When I use this as first output and use my background plate as second output and use S-Over in Viewer3 it produces exactly what I am aiming for and it looks beautiful (see fig 2).

However when trying to replicate it with Merge (over) node I get really washed out sky instead of intended mountains (see fig 3 and Viewer3). It seems that I have set something bad but I am not sure what. I suspect that premultiplied/unpremultiplied business, but I have no idea what is it.

Can somebody please help me? I am ready to answer any question about nodes in my project.

You can check if it’s a premult issue by adding a grade node to the matte and increasing the offset parameter. If you see any kind of change in the matte where there should be transparency, then you have a premult issue and you need to unpremult the matte. However I don’t think premult has got to do anything with the mountains. Either the shot doesn’t have enough data to help the keyer distinguish between the sky and the mountains or the matte needs more refinement. Hate to say this but if there isn’t enough data or if the shot is just exposed a certain way or if environmental conditions weren’t good when it was shot, the best thing to do would be to roto it.