Refactor and some comments