fix declaring global after function