added some more comments and edited the code with codePro