Fixed a buffer overflow due to inaccurate calculations.