Fixed gmp math bugs