cleaned code and renamed some variables