optimize: adding automatic gradient checking code