Fixed some variables not being local