typos, minor refactoring