Fix gradient calculation (works with inner part of cost, not squared +
weighted version)