Shouldn't you be passing dv into this function? Also, dv is not defined in the context of some of your calcDv calls, so it's unclear what should happen in those cases