Replace long implementation with BigInteger