Performing some operations on larger numbers gave erroneous results when converting from doubles to ints. Now uses longs instead, which should help.