fixed return types of energy and gradient to make it work with Cpp minimizer