Added a lot of comments and explanations