Refactor classes and add some comments