even cleaner gradient checking code and comments