Fixing possible log of zero error