code quality improvements and refactorings