added safeguards to max energy check and added workaround for visit bins with zero energy levels inside them.