Typos and function refactoring