Added comments and tested

Cosmetic changes to code, written function descriptions in the file.
Tested the functions' behaviour, results as intended.