Fixed several bugs in the test functions. check_grad now using relative error