Small refactoring and added some comments