factored discretization code