add utilities and gradient checking