Moved grid scalar out of loop