Refactor and fixed typo