fix tests, split out gradient computations