General refactorings and adding comments