fixed g function