Refactoring and fixed typo