Various minor refactoring