Reformatted the source and renamed some variables for more readable code