Refactor for better organization and readability, DRY