Significant addition of comments and refactoring of code