Updated code

Updated the code to have more comments and explain it better