move variable declaration to the beginning of the function (issue #5299)