[fix] Fix division by zero, and other small fixes