fix for a division by 0 exception on some special cases