Added more code comments and renamed some variables.