upgraded G-algo