Refactor for better structure and clarity