Remade math logic