Refactorings and code quality improvements