Renamed some variables, removed some superfluous code and added comments