small tuneups and refactoring