Added some comments and clarified function names.