Make sure the end cap is very carefully closed. wipe the contact springs with a little alcohol. Try a different brand of batteries. Some of the contact buttons on the ends of batteries are longer than others. Try and find the longer ones. Don't get fingerprints on the contacts after wiping them with alcohol.
If you ride in very cold wether and then bring your bike into the warm house condensation may get the batteries wet. Open it up, take the batteries out and let it dry overnight.