Code restructure for maintainability