Renamed some variables, better code organization