Fixed function being declared in the wrong scope