Made stats() numerically stable