sampling fixes
divide by zero checks