For your flat beers you may have crossed the line of too long of a primary/secondary. The longer you let it settle and yeast fall out of suspension the fewer you get into your bottles. The few starting yeast in the bottle the longer it would take for them to consume all the sugar and carb up the beer.
As for the bottle bombs it's hard to say. I have gone round and round with folks about bottle conditioning temperatures and it's effects. However the majority of them will say one of two things; 1.You bottled too soon or 2. Your sanitation is off and you have "bad germs" making extra CO2.
There is really no trick to it per say. There is still an amount of guessing going on with the quantity of yeast in the bottle. Time might be your friend in this case, let the flat ones set another few weeks to see if they catch up. Standardizing the brew schedule might help also, such as every brew gets the same amount of fermentation time. The only other thing is make the next step by taking the yeast out of the equation and start to keg.