Refactoring and enhancements