typos and minor refactorings