renamed some variables and fixed minor issues