fix division by 0 bug