Refactoring to simplify the codebase