Fixed error in code where variable 'g' would be called before assignement