Fixed a formula returning nan and messing up the calculatins