Comprehensive refactoring