rewrote the main formula