improve with switch, don't import math modulo f