refactorings and other improvements