Fix incorrect gradient calculation, and add optional 'use_log' argument (this actually has impact! wow)