changed to use long instead of float to avoid floating point errors showing up algorithmic errors