Fix variable usage before it defined

Sorry for that bug from my pull request. Now I checked it and it works great.