Move g() to functions