Fixed bug where floating point errors accumulated