Altered some variables to have more local scope