Fix sg is not defined