updated math logic