Fixed a JS bug that prevented calculations from working properly in some situations.