minor improvements and refactorings.