Adding sgl insertion code