completed the functions and tested working
added comments