Added detailed comments and overview of the 2 functions.