moved scope
refactored and fixed bug which came from bad naming
fixed small variable bug