Rearranged equations for possibly better numerical stability