Refactorings and style improvements