Fixed bug with calculateFlex