Improvements and refactorings