refactoring and added more descriptive comments