Renamed some functions and added some comments.