Added commenting for the functions to make the purpose and how they work more clear to the reader.