Move some variables and add a few comments