Added lots of comments describing functions