port most of the zeta function code