various small code refactoring