renamed some variables and made some improvements