Refactor code and fix a spelling mistake