Added some commentaries and performed a short refactoring section.