changed missing(g) to is.null(g)