First G-algo version. Need to test