fixed nasty floating point calculation bug