fixes to make optimization actually work
returning gradient None confuses optimizers, so return zeros instead