There are some crucial considerations to observe when fitting cables.
1. When cutting housing, make sure the hole hasn't been flattened, and use something sharp to ensure the crushed lining is opened up to a flare.
2. Housing ends need to be ground flat, preferably with ferrules fitted.
3. Housing length matters a lot - you need to determine the length that maximises the radius of all bends. Many bikes have a loop at the derailleur that's too short.