some refactorings and fix typos