Small improvements and refactorings