Refactor all the methods and add comments.