Minor improvements and refactorings