Moving global declaration to return from function