Calulation successfully ported from Python