changed log2 to log, and g==0 condition