It would be more efficient to put this calculation inside the if below, so we only do it if the ratios match.