Main coming out at apogee can be caused by many factors. The most likely are:
In fiberglass rockets, 4" and above, I usually use 3 #4 on the main separation point and 2 #2 at the apogee separation point. You still need to use enough tape on the couplers to snug up the fit until the joint slowly slides apart under the weight of the rocket. You do not want a sloppy fit as the jerk when the drogue deploys will shear the apogee pins. For cardboard rockets I use masking tape for a friction fit. You want the apogee separation point to be tight. The ejection charge will separate it even if you can't pull it out yourself. Use plenty of BP. Better a little too much than not enough. I always make my apogee shock cord very long, typically 50'. The main doesn't have to be very long, I usually use about 15'. This is nylon, Kevlar puts a lot more load on the attachment points.
Separation at motor burnout is caused by negative g's when the motor burns out. A snug slip fit helps here also and usually eliminates the need for shear pins. On my 6" and 7.5" fiberglass rockets, I use the 2 #2 at apogee and 3 #4 at main. When using a long burn motor there is a good chance of an arcing flight where the rocket is moving pretty fast even at apogee. In these cases I double the main pins to 6 #4 and leave the apogee alone. (Think N1000 or M750 or my Rx N800.)