refactored for maintainability