fixed errors in bp
improve run time for gradient checking