Is there a way to improve collision accuracy?

I have been trying to create a 2D and 3D Gas model and have run into some issues with conservation of energy laws. The system seems to gain energy if restitution is set to 1 (More stable at 0.96 but still fluctuates around too much). I have applied a fix with a thermostat type function running every time step, as can be seen in the below code:
However, I was wondering whether there are any better solutions? Such as a way to edit the accuracy of the physics engine to be more accurate in its calculations.
Thanks in advance,
P.s. Here is a link to the full project in case it is useful:

If you need something that is scientifically accurate, you most likely need to write your own physics or find another 3rd party. The one that PlayCanvas uses is ammo.js which is a JS compiled version of Bullet used for games.